package app;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;

import javax.swing.JComponent;

import com.dinim.matrix.Matrix;
import com.dinim.matrix.twodimensional.Vector3;

public class MatrixComponent extends JComponent{


	public void paint(Graphics g) {
		Graphics2D g2 = (Graphics2D)g;
		g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
						    RenderingHints.VALUE_ANTIALIAS_ON);
		
		
		g.fillRect(0, 0, getWidth(), getHeight());
		g.setColor(Color.GREEN.darker());
		
		double x = 150;
		double y = 150;
		double width = 100;
		double height = 100;
		
		Vector3[] nodes = new Vector3[4];
		
		nodes[0] = new Vector3(x,y);
		nodes[1] = new Vector3(x+width,y);
		nodes[2] = new Vector3(x+width,y+height);
		nodes[3] = new Vector3(x,y+height);
		

		
//		Rectangle2D rect = new Rectangle2D(x,y,width,height);
//		rect.setReferencePoint(rect.getNodes()[0]);
//		rect.rotate(20);
//		draw(rect.getNodes(), g);
//		rect.rotate(270);
//		draw(rect.getNodes(), g);

	}
	
	private void transform(Vector3[] nodes, Matrix m){
		for (int i = 0; i < nodes.length; i++) {
			nodes[i].multiplyByMatrix(m);
		}
	}
	
	private void draw(Vector3[] nodes, Graphics g){
		
		for (int i = 0; i < nodes.length; i++) {
			if(i == nodes.length-1){
				g.drawLine((int)nodes[i].get(Vector3.X, Vector3.FRIST_COLUMN), (int)nodes[i].get(Vector3.Y, Vector3.FRIST_COLUMN), 
						   (int)nodes[0].get(Vector3.X, Vector3.FRIST_COLUMN), (int)nodes[0].get(Vector3.Y, Vector3.FRIST_COLUMN));
			}else{
				g.drawLine((int)nodes[i].get(Vector3.X, Vector3.FRIST_COLUMN), (int)nodes[i].get(Vector3.Y, Vector3.FRIST_COLUMN), 
						   (int)nodes[i+1].get(Vector3.X, Vector3.FRIST_COLUMN), (int)nodes[i+1].get(Vector3.Y, Vector3.FRIST_COLUMN));
			}	
		}
	}
}
